package com.battle.service.controller.web;

import com.battle.pojo.param.caseBaseInfo.CaseStatisticsParam;
import com.battle.pojo.param.caseBaseInfo.GetCaseDiscountingParam;
import com.battle.pojo.param.personWarCase.*;
import com.battle.pojo.vo.caseBaseInfo.CaseDiscountingVo;
import com.battle.pojo.vo.personWarCase.*;
import com.battle.service.service.in.*;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import nirvana.core.exceptions.BizException;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * web/人员战力表
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@RestController
@RequestMapping("/personWarCase/web")
@AllArgsConstructor
public class PersonWarCaseWebController {

    private final PersonWarCaseService service;

    /**
     * 创建人员战力表
     *
     * @param param
     * @return
     */
    @PostMapping("/createPersonWarCase")
    public ApiResult<Long> createPersonWarCase(@RequestBody @Valid CreatePersonWarCaseParam param) {
        Long id = service.createPersonWarCase(param);
        return ApiResult.ok(id);
    }


    /**
     * 修改人员战力表
     *
     * @param param
     */
    @PutMapping("/editPersonWarCase")
    public ApiResult editPersonWarCase(@RequestBody @Valid EditPersonWarCaseParam param) {
        service.editPersonWarCase(param);
        return ApiResult.ok();
    }

    /**
     * 移除人员战力表
     *
     * @param id
     */
    @DeleteMapping("/removePersonWarCase")
    public ApiResult removePersonWarCase(@RequestParam("id") Long id) {
        service.removePersonWarCase(id);
        return ApiResult.ok();
    }


    /**
     * 获取人员战力表详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getPersonWarCase")
    public ApiResult<GetPersonWarCaseVo> getPersonWarCase(@RequestParam("id") Long id) {
        GetPersonWarCaseVo vo = service.getPersonWarCase(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取人员战力表列表
     *
     * @param param
     * @return
     */
    @PostMapping("/getPersonWarCaseList")
    public ApiResult<PageResult<GetPersonWarCaseListVo>> getPersonWarCaseList(@RequestBody GetPersonWarCaseListParam param) {
        PageResult<GetPersonWarCaseListVo> result = service.getPersonWarCaseList(param);
        return ApiResult.ok(result);
    }

    /**
     * 导出人员战力
     * @param response
     * @param param
     */
    @PostMapping(value = "/exportPersonWarCaseList")
    public void exportPersonWarCaseList(HttpServletResponse response, @RequestBody GetPersonWarCaseListParam param) {
        try {
            service.exportPersonWarCaseList(param, response);
        } catch (IOException e) {
            throw new BizException(e.getMessage());
        }
    }

    /**
     * 获取人员战力表下拉列表
     *
     * @return
     */
    @PostMapping("/getPersonWarCaseDownList")
    public ApiResult<List<GetPersonWarCaseDownListVo>> getPersonWarCaseDownList(@RequestBody(required = false) @Valid GetPersonWarCaseDownListParam param) {
        List<GetPersonWarCaseDownListVo> list = service.getPersonWarCaseDownList(param);
        return ApiResult.ok(list);
    }


    /**
     * 获取组织架构下需要考试的人员列表
     *
     * @return
     */
    @PostMapping("/getPersonTrainingList")
    public ApiResult<List<GetPersonWarCaseDownListVo>> getPersonTrainingList(@RequestBody(required = false) @Valid GetPersonTrainingListParam param) {
        List<GetPersonWarCaseDownListVo> list = service.getPersonTrainingList(param);
        return ApiResult.ok(list);
    }

    /**
     * 根据评估参数重新计算人员指数和队伍指数车辆指数
     * @return
     */
    @GetMapping("/updateCombatPower")
    public ApiResult updateCombatPower() {
        service.updateCombatPower();
        return ApiResult.ok();
    }

    /**
     * 获取人员报告url
     * @param id
     * @return
     */
    @GetMapping("/getReportUrl")
    public ApiResult<String> getReportUrl(@RequestParam("id") Long id) {
        String vo = service.getReportUrl(id);
        return ApiResult.ok(vo);
    }

    /**
     * 战力折线图
     *
     * @return
     */
    @PostMapping("/getWarCaseNumber")
    public ApiResult<CaseDiscountingVo> getWarCaseNumber(@RequestBody(required = false) @Valid GetCaseDiscountingParam param) {
        CaseDiscountingVo list = service.getWarCaseNumber(param);
        return ApiResult.ok(list);
    }

    /**
     * 战力统计饼图
     *
     * @return
     */
    @PostMapping("/getWarCaseDetailsNumber")
    public ApiResult<List<GetPersonWarCaseDetailsVo>> getWarCaseDetailsNumber(@RequestBody(required = false) @Valid CaseStatisticsParam param) {
        List<GetPersonWarCaseDetailsVo> list = service.getWarCaseDetailsNumber(param);
        return ApiResult.ok(list);
    }

    /**
     * 导入人员战力表
     *
     * @param file
     * @return
     */
    @PostMapping("/importPersonWarCase")
    public void importPersonWarCase(@RequestParam("file") MultipartFile file) {
        service.importPersonWarCase(file);
    }
}

